<template>
  <div v-loading="loading">
    <el-form ref="form" :model="form" :rules="rules" label-width="120px" class="dataForm">
      <el-row>
        <el-col :span="12">
          <el-form-item :label="$t('开始时间')" prop="startDate">
            <el-date-picker
              v-model="form.startDate"
              clearable
              style="width: 200px"
              type="date"
              value-format="yyyy-MM-dd"
              :placeholder="$t('开始时间')"
            />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('结束时间')" prop="endDate">
            <el-date-picker
              v-model="form.endDate"
              clearable
              style="width: 200px"
              type="date"
              value-format="yyyy-MM-dd"
              :placeholder="$t('结束时间')"
            />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('学校')" prop="eduCollege">
            <el-input v-model="form.eduCollege" :placeholder="$t('学校')" show-word-limit maxlength="50" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('学校类型')">
            <el-select v-model="form.eduCollegeType" value="" :placeholder="$t('学校类型')">
              <el-option
                v-for="dict in collegeTypeOptions"
                :key="dict.dictValue"
                :label="$t(dict.dictLabel)"
                :value="dict.dictValue"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('院系')" prop="eduCollegeDept">
            <el-input v-model="form.eduCollegeDept" :placeholder="$t('院系')" show-word-limit maxlength="50" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('专业')" prop="eduMajor">
            <el-input v-model="form.eduMajor" :placeholder="$t('专业')" show-word-limit maxlength="50" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('是否统招')" prop="eduRecruit">
            <el-input v-model="form.eduRecruit" :placeholder="$t('是否统招')" show-word-limit maxlength="25" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('学历')" prop="eduDegree">
            <el-input v-model="form.eduDegree" :placeholder="$t('学历')" show-word-limit maxlength="25" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('备注')" prop="remark">
            <el-input v-model="form.remark" type="textarea" maxlength="2000" show-word-limit :placeholder="$t('备注')" />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div slot="footer" class="dialog-footer" style="text-align: right;">
      <!--保存 取消按钮-->
      <save-btn has-permi="resume:eduExperience" />
    </div>
  </div>
</template>

<script>
    import { saveResumeEduExperience, getResumeEduExperience } from '@/api/oa/resume/eduExperience/resumeEduExperience'
    export default {
        data() {
          return {
            // 表单参数
            form: {},
            // 毕业院校类型
            collegeTypeOptions: [],
            // 遮罩层
            loading: false,
            // 表单校验
            rules: {
              startDate: [{ required: true, message: this.$t('必填信息'),	trigger: 'blur' }],
              endDate: [{ required: true, message: this.$t('必填信息'),	trigger: 'blur' }],
              eduCollege: [{ required: true, message: this.$t('必填信息'),	trigger: 'blur' }]
            }
          }
        },
        created() {
          // 毕业院校类型
          this.getDicts('college_type').then(response => {
            this.collegeTypeOptions = response.data
          })
        },
        methods: {
            // 初始化数据
            init(data) {
                if (data != null && data.id !== undefined) {
                    this.loading = true
                    getResumeEduExperience(data.id).then(response => {
                        this.form = response.data
                        this.loading = false
                    })
                } else {
                    this.reset()
                }
            },
            // 表单重置
            reset() {
                this.form = {
                    id: undefined,
                    resumeId: this.$route.query.resumeId,
                    startDate: undefined,
                    endDate: undefined,
                    eduCollege: undefined,
                    eduCollegeType: undefined,
                    eduCollegeDept: undefined,
                    eduMajor: undefined,
                    eduRecruit: undefined,
                    eduDegree: undefined,
                    remark: undefined,
                    createBy: undefined,
                    updateBy: undefined,
                    createTime: undefined,
                    updateTime: undefined,
                    delFlag: undefined
                }
                this.resetForm('form')
            },
            // 取消按钮
            cancel() {
                this.$parent.$parent.formOpen = false
                this.$parent.$parent.reset()
            },
            // 关闭form页面
            closeForm() {
                // 关闭form页面遮罩层
                this.loading = false
                // 关闭form页面
                if (this.$parent.$parent.formOpen !== undefined) {
                  this.$parent.$parent.formOpen = false
                }
                // 刷新list页面
                if (this.$parent.$parent.getList !== undefined) {
                  this.$parent.$parent.getList()
                }
            },
            /** 提交按钮 */
            submitForm: function() {
                this.$refs['form'].validate(valid => {
                    if (valid) {
                        this.loading = true
                        saveResumeEduExperience(this.form).then(response => {
                            if (response.code === 200) {
                                this.msgSuccess(this.$t('保存成功'))
                                this.closeForm()
                            } else {
                                this.msgError(response.msg)
                            }
                            this.loading = false
                        })
                    } else {
                       this.locationError(document)
                    }
                })
           }

        }

    }
</script>
